package com.luozy.search.web;

import com.luozy.common.dto.PageDTO;
import com.luozy.search.pojo.ItemDoc;
import com.luozy.search.pojo.RequestParams;
import com.luozy.search.service.SearchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("search")
@Slf4j
public class SearchController {
    @Autowired
    private SearchService searchService;

    //1.ES基本搜索
    @PostMapping("/list")
    public PageDTO<ItemDoc> search(@RequestBody RequestParams params) {
        log.info("ES搜索：{}",params);
        return searchService.search(params);
    }

    //2.ES过滤项聚合(分类、品牌)
    @PostMapping("/filters")
    public Map<String, List<String>> filters(@RequestBody RequestParams params) {
        log.info("ES过滤项聚合：{}",params);
        return searchService.filters(params);
    }
}
